﻿using System;
using KingsSharp.Core.Data.Entity;
using CRM.Admin.Contracts.Model.Customer;

namespace CRM.Admin.Services.EntityConfigurations.Customer
{
    /// <summary>
    /// 顾客信息配置
    /// </summary>
    public class CustomerCfg : EntityConfigurationBase<Contracts.Model.Customer.Customer, Guid>
    {
        public CustomerCfg()
        {
            Property(t => t.AgreementFilishProfiles).HasMaxLength(2000);
            Property(t => t.BankLicenseImageUrl).HasMaxLength(2000);
            Property(t => t.Business).HasMaxLength(500);
            Property(t => t.Code).HasMaxLength(20);
            Property(t => t.CreditInfo).HasMaxLength(200);
            Property(t => t.CreditRatings).HasMaxLength(200);
            HasOptional(t => t.CustomerAddress).WithMany().HasForeignKey(f => f.CustomerAddressId);
            HasOptional(t => t.CustomerAddress1).WithMany().HasForeignKey(f => f.CustomerAddressId1);
            //Property(t => t.Demand).HasMaxLength(500);
            //Property(t => t.DemandFilePath).HasMaxLength(2000);
            Property(t => t.LegalMan).HasMaxLength(50);
            Property(t => t.Name).HasMaxLength(80);
            Property(t => t.OrganizationCode).HasMaxLength(50);
            Property(t => t.OrganizationImageUrl).HasMaxLength(200);
            HasOptional(t => t.ParentCustomer).WithMany().HasForeignKey(f => f.ParentId);
            //Property(t => t.Profiles).HasMaxLength(500);
            //Property(t => t.ProfilesAttachment).HasMaxLength(2000);
            Property(t => t.Remark).HasMaxLength(500);
            Property(t => t.SaleSysCode).HasMaxLength(50);
            Property(t => t.Scale).HasMaxLength(120);
            Property(t => t.ShortName).HasMaxLength(50);
            Property(t => t.TaxRegistrationCode).HasMaxLength(50);
            Property(t => t.TaxRegistrationImageUrl).HasMaxLength(200);
            Property(t => t.TicketAttachment).HasMaxLength(500);
            Property(t => t.TicketBank).HasMaxLength(50);
            Property(t => t.TicketBankAccount).HasMaxLength(30);
            Property(t => t.Type).HasMaxLength(120);
            Property(t => t.CooperationState).HasMaxLength(500);
        }
    }

    /// <summary>
    /// 顾客履历配置
    /// </summary>
    public class ResumeConfigCfg : EntityConfigurationBase<ResumeConfig, Guid>
    {
        public ResumeConfigCfg()
        {
            Property(t => t.ClassName).HasMaxLength(120);
            Property(t => t.FieldKey).HasMaxLength(80);
        }
    }
    /// <summary>
    /// 顾客履历
    /// </summary>
    public class CustomerResumeCfg : EntityConfigurationBase<CustomerResume, Guid>
    {
        public CustomerResumeCfg()
        {
            Property(t => t.FieldKey).HasMaxLength(80);
            HasRequired(t => t.UserInfo).WithMany().HasForeignKey(f => f.UserInfoId);
        }
    }
    /// <summary>
    /// 顾客简介
    /// </summary>
    public class CustomerProfilesCfg : EntityConfigurationBase<CustomerProfiles, Guid>
    {
        public CustomerProfilesCfg()
        {
            Property(t => t.Profiles).HasMaxLength(2000);
            Property(t => t.ProfilesAttachment).HasMaxLength(500);
            HasRequired(t => t.Customer).WithMany().HasForeignKey(f => f.CustomerId);
        }
    }
    /// <summary>
    /// 顾客性质基础
    /// </summary>
    public class NatureCatalogCfg : EntityConfigurationBase<NatureCatalog, Guid>
    {
        public NatureCatalogCfg()
        {
            Property(t => t.Code).HasMaxLength(20);
            Property(t => t.Description).HasMaxLength(200);
            Property(t => t.Name).HasMaxLength(80);
            HasOptional(t => t.Parent).WithMany().HasForeignKey(f => f.ParentId);
        }
    }
    /// <summary>
    /// 顾客性质值子表
    /// </summary>
    public class NatureCfg : EntityConfigurationBase<Nature, Guid>
    {
        public NatureCfg()
        {
            Property(t => t.Value).HasMaxLength(200);
            HasRequired(t => t.NatureCatalog).WithMany(l => l.Natures).HasForeignKey(f => f.NatureCatalogId);
        }
    }

    /// <summary>
    /// 顾客对应性质表
    /// </summary>
    public class CustomerNatureCfg : EntityConfigurationBase<CustomerNature, Guid>
    {
        public CustomerNatureCfg()
        {
            HasRequired(t => t.Customer).WithMany(l => l.CustomerNatures).HasForeignKey(f => f.CustomerId);
            HasRequired(t => t.Nature).WithMany().HasForeignKey(f => f.NatureId);
        }
    }
    /// <summary>
    /// 顾客协议
    /// </summary>
    public class CustomerAgreementCfg : EntityConfigurationBase<CustomerAgreement, Guid>
    {
        public CustomerAgreementCfg()
        {
            Property(t => t.ProdName).HasMaxLength(50);
            Property(t => t.ProtocolQuantity).HasPrecision(18, 2);
            Property(t => t.CompletionQuantity).HasPrecision(18, 2);
            HasRequired(t => t.Customer).WithMany().HasForeignKey(f => f.CustomerId);
        }
    }

    public class CustomerAddressConfiguration : EntityConfigurationBase<CustomerAddress, Guid>
    {
        public CustomerAddressConfiguration()
        {
            this.Property(a => a.Borough).HasMaxLength(80);
            this.Property(a => a.BoroughCode).HasMaxLength(30);

            this.Property(a => a.City).HasMaxLength(80);
            this.Property(a => a.CityCode).HasMaxLength(30);

            this.Property(a => a.Community).HasMaxLength(80);
            this.Property(a => a.CommunityCode).HasMaxLength(30);
            this.Property(a => a.Description).HasMaxLength(200);

            this.Property(a => a.Province).HasMaxLength(80);
            this.Property(a => a.ProvinceCode).HasMaxLength(30);

            this.Property(a => a.Street).HasMaxLength(80);
            this.Property(a => a.StreetCode).HasMaxLength(30);

            this.Property(a => a.Province1).HasMaxLength(80);
            this.Property(a => a.ProvinceCode1).HasMaxLength(30);

            this.Property(a => a.City1).HasMaxLength(80);
            this.Property(a => a.CityCode1).HasMaxLength(30);

            this.Property(a => a.Borough1).HasMaxLength(80);
            this.Property(a => a.BoroughCode1).HasMaxLength(30);

            this.Property(a => a.Street1).HasMaxLength(80);
            this.Property(a => a.StreetCode1).HasMaxLength(30);

            this.Property(a => a.Description1).HasMaxLength(200);

        }
    }

    /// <summary>
    /// 联系人
    /// </summary>
    public class LinkManCfg : EntityConfigurationBase<LinkMan, Guid>
    {
        public LinkManCfg()
        {
            Property(t => t.Address).HasMaxLength(200);
            Property(t => t.Department).HasMaxLength(50);
            Property(t => t.Email).HasMaxLength(50);
            Property(t => t.Fax).HasMaxLength(50);
            Property(t => t.Job).HasMaxLength(50);
            Property(t => t.Name).HasMaxLength(50);
            Property(t => t.Phone).HasMaxLength(30);
            Property(t => t.PostCode).HasMaxLength(15);
            Property(t => t.Tel).HasMaxLength(15);
            Property(t => t.QQnumber).HasMaxLength(50);
            HasRequired(t => t.Customer).WithMany(l => l.LinkMans).HasForeignKey(f => f.CustomerId);
        }
    }
    /// <summary>
    /// 顾客归属
    /// </summary>
    public class AscriptionCfg : EntityConfigurationBase<Ascription, Guid>
    {
        public AscriptionCfg()
        {
            Property(t => t.DeputyName).HasMaxLength(50);
            HasRequired(t => t.Organization).WithMany().HasForeignKey(f => f.OrganizationId);
        }
    }

    /// <summary>
    /// 竞争对手情况
    /// </summary>
    public class CompetitorCfg : EntityConfigurationBase<Competitor, Guid>
    {
        public CompetitorCfg()
        {
            Property(t => t.Name).HasMaxLength(100);
            Property(t => t.ContractDelivery).HasMaxLength(200);
            Property(t => t.ContractDeliveryPath).HasMaxLength(100);
            Property(t => t.MarketStrategy).HasMaxLength(200);
            Property(t => t.MarketStrategyPath).HasMaxLength(100);
            Property(t => t.Problem).HasMaxLength(200);
            Property(t => t.ProblemPath).HasMaxLength(100);
            Property(t => t.ProQualityLevel).HasMaxLength(200);
            Property(t => t.ProQualityLevelPath).HasMaxLength(100);
            Property(t => t.SupplyDesc).HasMaxLength(200);
            Property(t => t.SupplyDescPath).HasMaxLength(100);
            Property(t => t.SupplyRelation).HasMaxLength(200);
            Property(t => t.SupplyRelationPath).HasMaxLength(100);
            Property(t => t.ProductShare).HasPrecision(8, 2);
            HasRequired(t => t.Customer).WithMany(l => l.Competitors).HasForeignKey(f => f.CustomerId);
        }
    }

    /// <summary>
    /// 服务管理
    /// </summary>
    public class ServeMgCfg : EntityConfigurationBase<ServeMg, Guid>
    {
        public ServeMgCfg()
        {
            Property(t => t.Type).HasMaxLength(20);
            Property(t => t.CustomPerson).HasMaxLength(200);
            Property(t => t.CustomPersonPath).HasMaxLength(100);
            Property(t => t.PgPerson).HasMaxLength(200);
            Property(t => t.PgPersonPath).HasMaxLength(100);
            Property(t => t.Report).HasMaxLength(200);
            Property(t => t.ReportPath).HasMaxLength(100);
            HasRequired(a => a.Customer).WithMany(l => l.ServeMgs).HasForeignKey(f => f.CustomerId);
        }
    }
}
